package com.ruoyi.web.controller.base;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;

import java.util.Date;
import java.util.List;
import java.util.Arrays;

import com.ruoyi.common.utils.SecurityUtils;
import com.ruoyi.common.utils.StringUtils;
import com.ruoyi.system.domain.base.MesScanKeysRelation;
import com.ruoyi.system.domain.base.MesScanKeysRelationDTO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.system.service.IMesScanKeysRelationService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 关重件扫描验证关系Controller
 *
 * @author ruoyi
 * @date 2023-02-16
 */
@Api(tags = "关重件扫描验证关系api")
@RequiredArgsConstructor(onConstructor_ = @Autowired)
@RestController
@RequestMapping("/base/relation" )
public class MesScanKeysRelationController extends BaseController {

    private final IMesScanKeysRelationService iMesScanKeysRelationService;

    /**
     * 查询关重件扫描验证关系列表
     */
    @ApiOperation(value = "查询关重件扫描验证关系列表")
    @GetMapping("/list")
    public TableDataInfo list(MesScanKeysRelation mesScanKeysRelation)
    {
        startPage();
        List<MesScanKeysRelationDTO> list = iMesScanKeysRelationService.getList(mesScanKeysRelation);
        return getDataTable(list);
    }

    /**
     * 导出关重件扫描验证关系列表
     */
    @Log(title = "关重件扫描验证关系" , businessType = BusinessType.EXPORT)
    @GetMapping("/export" )
    public AjaxResult export(MesScanKeysRelation mesScanKeysRelation) {
        LambdaQueryWrapper<MesScanKeysRelation> lqw = new LambdaQueryWrapper<MesScanKeysRelation>(mesScanKeysRelation);
        List<MesScanKeysRelation> list = iMesScanKeysRelationService.list(lqw);
        ExcelUtil<MesScanKeysRelation> util = new ExcelUtil<MesScanKeysRelation>(MesScanKeysRelation. class);
        return util.exportExcel(list, "relation" );
    }

    /**
     * 获取关重件扫描验证关系详细信息
     */
    @ApiOperation(value = "获取关重件扫描验证关系详细信息")
    @GetMapping(value = "/{id}" )
    public AjaxResult getInfo(@PathVariable("id" ) Long id) {
        return AjaxResult.success(iMesScanKeysRelationService.getById(id));
    }

    /**
     * 新增关重件扫描验证关系
     */
    @ApiOperation(value = "新增关重件扫描验证关系")
    @Log(title = "关重件扫描验证关系" , businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody MesScanKeysRelation mesScanKeysRelation) {
        mesScanKeysRelation.setCreateBy(SecurityUtils.getUsername());
        mesScanKeysRelation.setCreateTime(new Date());
        return toAjax(iMesScanKeysRelationService.save(mesScanKeysRelation) ? 1 : 0);
    }

    /**
     * 修改关重件扫描验证关系
     */
    @ApiOperation(value = "修改关重件扫描验证关系")
    @Log(title = "关重件扫描验证关系" , businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody MesScanKeysRelation mesScanKeysRelation) {
        mesScanKeysRelation.setUpdateBy(SecurityUtils.getUsername());
        mesScanKeysRelation.setUpdateTime(new Date());
        return toAjax(iMesScanKeysRelationService.updateById(mesScanKeysRelation) ? 1 : 0);
    }

    /**
     * 删除关重件扫描验证关系
     */
    @ApiOperation(value = "删除关重件扫描验证关系")
    @Log(title = "关重件扫描验证关系" , businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}" )
    public AjaxResult remove(@PathVariable Long[] ids) {
        return toAjax(iMesScanKeysRelationService.removeByIds(Arrays.asList(ids)) ? 1 : 0);
    }
}
